/**
 * @file progressCardList
 * @author caierwei(caierwei@baijia.com)
 * @date 2020-01-07
 */
import React from 'react';
import {Row} from 'antd';

import CommonCard from '../../../common/CommonCard';
import ProgressComponent from './ProgressComponent';

const ProgressCardList = props => {
    const {
        dataSource,
        loading,
        span,
        onDownload,
        onDetail,
    } = props;

    return (
        <Row>
            {
                dataSource?.map((item, index) => {
                    const {unitName, unitId, cardValues} = item;
                    const {value} = cardValues.length ? cardValues[0] : {value: 0};
                    const Content = (
                        <ProgressComponent
                            percent={(Number(value) * 100).toFixed(2)}
                        />
                    );
                    return (
                        <CommonCard
                            loading={loading}
                            title={unitName}
                            cardId={unitId}
                            span={span}
                            content={Content}
                            onDownload={onDownload}
                            onDetail={onDetail}
                            // eslint-disable-next-line
                            key={index}
                        />
                    );
                })
            }
        </Row>
    );
};

export default ProgressCardList;

